chrome.extension.onMessage.addListener(function(request, sender) {
 if (request.action == "getPName") {
  //  message.innerText = request.source;;
	productName.innerText = request.source;
	var PName = document.getElementById("PName");

		var al = document.getElementById("al");
		al.setAttribute("style", "display:none;");
		var dm = document.getElementById("dialog-modal");
		dm.setAttribute("style", "font-size:62.5%;");

	PName.setAttribute("value", productName.innerText);
  }
  if(request.action == "getPPrice"){
	productPrice.innerText = request.source;
	var PPrice = document.getElementById("PPrice");
	PPrice.setAttribute("value", productPrice.innerText);
  }
  if(request.action == "getImageURL"){
	productImage.setAttribute("src", request.source);
	var PImage = document.getElementById("PImage");
	PImage.setAttribute("value", productImage.getAttribute("src"));
  }
 
});

 chrome.tabs.getSelected(null,function(tab) {
    var tablink = tab.url;
	var productLink = document.querySelector('#productLink');
	productLink.setAttribute("href", tablink);
	var PURL = document.getElementById("PURL");
	PURL.setAttribute("value", tablink);
});


//chrome.tabs.getSelected(null,function(tab) {
//    var tablink = tab.url;
//	var productLink = document.querySelector('#productLink');
//	productLink.setAttribute("href", tablink);
//	alert(tablink);
//});



function onWindowLoad() {

  //var message = document.querySelector('#message');
  var productName = document.querySelector('#productName');
  var productPrice = document.querySelector('#productPrice');
   var productImage = document.querySelector('#productImage');
   var btTrack = document.querySelector('#btTrack');
			
  chrome.tabs.executeScript(null, {
    file: "getPagesSource.js"
  }, function() {
    // If you try and inject into an extensions page or the webstore/NTP you'll get an error
    if (chrome.extension.lastError) {
      message.innerText = 'There was an error injecting script : \n' + chrome.extension.lastError.message;
    }
  });

}

window.onload = onWindowLoad;